package main

import "fmt"

type Rec struct {
	w, h int
}

func (rec Rec) area() int {
	return rec.w * rec.h
}

type RecSub struct {
	Rec
	z int
}

func (rec RecSub) area() int {
	//rec.h = rec.h / 2
	return rec.w * rec.h * rec.z
}
func (rec *Rec) setH() {
	rec.h = rec.h / 2
}

type Age int //基础类型 也能作为对象（接受者）

func (age Age) value() int {
	return 0
}

//interface start
type Add interface {
	add()
}

type Add2 interface {
	add()
}

func (rec Rec) add() int {
	return rec.w + rec.h
}

//interface end

//goroutine
func testGoroutine() {
	fmt.Println(" hello test goroutine")
}

func main() {
	rec := Rec{2, 4}
	fmt.Println("rec.area =", rec.area())

	var age Age = 4
	fmt.Println("age =", age.value())

	//继承
	recS := RecSub{Rec{2, 4}, 2}
	fmt.Println("recS.area =", recS.area())
	fmt.Println("recS.rec.area =", recS.Rec.area())
	recS.setH()
	fmt.Println("recS.area =", recS.area())

	//recS2 := RecSub{ 2}
	//interface start
	recI := Rec{2, 4}
	fmt.Println("recI =", recI.add())

	/*
		var add Add
		add = recI
		fmt.Println("add =", recI.add())

		var add2 Add2
		add2 = recI
		fmt.Println("adde =", recI.add())
		//*/
	//interface end
	go testGoroutine()
	//testGoroutine()
}
